package fudan.se.lab2.controller;

import fudan.se.lab2.controller.request.InviteRequest;
import fudan.se.lab2.controller.request.ProcessInvitationRequest;
import fudan.se.lab2.domain.Invitation;
import fudan.se.lab2.domain.Meeting;
import fudan.se.lab2.domain.User;
import fudan.se.lab2.service.InviteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class InviteController {
    private final InviteService inviteService;

    @Autowired
    public InviteController(InviteService inviteService) {
        this.inviteService = inviteService;
    }

    @PostMapping("/invite")
    public ResponseEntity<Meeting> invite(@RequestBody InviteRequest request) {
        return ResponseEntity.ok(inviteService.invite(request));
    }

    @PostMapping("/agreeInvitation")
    public ResponseEntity<String> agreeInvitation(@RequestBody ProcessInvitationRequest request) {
        return ResponseEntity.ok(inviteService.agreeInvitation(request.getUsername(), request.getMeetingFullName(), request.getTopics()));
    }

    @PostMapping("rejectInvitation")
    public ResponseEntity<String> rejectInvitation(@RequestBody ProcessInvitationRequest request) {
        return ResponseEntity.ok(inviteService.rejectInvitation(request.getUsername(), request.getMeetingFullName()));
    }

    @PostMapping("/alreadyInvitedUsers")
    public ResponseEntity<List<User>> alreadyInvitedUsers(@RequestBody String meetingFullName) {
        return ResponseEntity.ok(inviteService.alreadyInvitedUsers(meetingFullName));
    }

    @PostMapping("/notInvitedUsers")
    public ResponseEntity<List<User>> notInvitedUsers(@RequestBody String meetingFullName) {
        return ResponseEntity.ok(inviteService.notInvitedUsers(meetingFullName));
    }

    @PostMapping("/invitationISent")
    public ResponseEntity<List<Invitation>> invitationISent(@RequestBody String username) {
        return ResponseEntity.ok(inviteService.invitationISent(username));
    }
}
